//
//  LGRecipeMedicineAddCell.m
//  XieHeHeartDisease
//
//  Created by 1234 on 2024/3/4.
//

#import "LGRecipeMedicineAddCell.h"

@interface LGRecipeMedicineAddCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *doseLabel;
/**   */
@property (nonatomic , strong)UIImageView *editView;
/**   */
@property (nonatomic , strong)UILabel *timeTitle;
/**   */
@property (nonatomic , strong)UILabel *takeLabel;
/**   */
@property (nonatomic , strong)UILabel *remarkLabel;
/**   */
@property (nonatomic , strong)UIView *lineView;
/**   */
@property (nonatomic , strong)UILabel *stopTime;
/**   */
@property (nonatomic , strong)UILabel *continueLabel;

@end

@implementation LGRecipeMedicineAddCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.nameLabel.text = LGNSString(dataDic[@"title"]);
    self.doseLabel.text = LGNSString(dataDic[@"dose"]);
    self.timeTitle.text = LGNSString(dataDic[@"take_frequency"]);
    self.takeLabel.text = LGNSString(dataDic[@"take_method"]);
    NSString *remark = LGNSString(dataDic[@"remark"]);
    CGFloat remarkTop = (remark.length>0)?viewPix(8):0;
    [self.remarkLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.takeLabel.mas_bottom).offset(remarkTop);
    }];
    self.remarkLabel.text = remark;
    NSString *stopTime = LGNSString(dataDic[@"stop_time"]);
    CGFloat bottom = (stopTime.length>0)?-viewPix(50):0;
    self.lineView.hidden = (stopTime.length>0)?NO:YES;
    [self.lineView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.baseView).offset(bottom);
    }];
    
    self.stopTime.text = [NSString stringWithFormat:@"服用时间：%@",dataDic[@"stop_time"]];
}

-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.iconView];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.doseLabel];
    [self.baseView addSubview:self.editView];
    [self.baseView addSubview:self.timeTitle];
    [self.baseView addSubview:self.takeLabel];
    [self.baseView addSubview:self.remarkLabel];
    [self.baseView addSubview:self.lineView];
    [self.baseView addSubview:self.stopTime];
    [self.baseView addSubview:self.continueLabel];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.top.equalTo(self.contentView).offset(viewPix(8));
        make.bottom.equalTo(self.contentView).offset(-viewPix(8));
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(viewPix(10));
        make.centerY.equalTo(self.iconView);
        make.width.lessThanOrEqualTo(@(Screen_W-viewPix(200)));
    }];
    [self.doseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(6));
        make.centerY.equalTo(self.iconView);
    }];
    [self.editView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.iconView);
        make.right.equalTo(self.baseView).offset(-viewPix(12));
    }];
    [self.timeTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView.mas_bottom).offset(viewPix(8));
        make.left.equalTo(self.iconView);
    }];
    [self.takeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.timeTitle.mas_right).offset(viewPix(10));
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.top.equalTo(self.timeTitle);
    }];

    [self.remarkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.takeLabel.mas_bottom).offset(viewPix(8));
        make.left.equalTo(self.iconView);
        make.right.equalTo(self.takeLabel);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.remarkLabel.mas_bottom).offset(viewPix(10));
        make.left.right.equalTo(self.remarkLabel);
        make.height.equalTo(@(0.5));
        make.bottom.equalTo(self.baseView).offset(-viewPix(50));
    }];
    [self.stopTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineView.mas_bottom).offset(viewPix(15));
        make.left.equalTo(self.lineView);
    }];
    [self.continueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.stopTime);
        make.width.equalTo(@(viewPix(76)));
        make.height.equalTo(@(viewPix(30)));
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 10;
    }
    return _baseView;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"用药管理-药品"]];
        _iconView.frame = CGRectMake(viewPix(12), viewPix(12), viewPix(32), viewPix(32));
    }
    return _iconView;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:2];
    }
    return _nameLabel;
}

-(UILabel *)doseLabel{
    if(!_doseLabel){
        _doseLabel = [UILabel lableWithText:@"" colorString:@"#909399" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _doseLabel;
}

-(UIImageView *)editView{
    if(!_editView){
        _editView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"用药管理-编辑"]];
    }
    return _editView;
}

-(UILabel *)timeTitle{
    if(!_timeTitle){
        _timeTitle = [UILabel lableWithText:@"每天" colorString:@"#282828" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _timeTitle;
}

-(UILabel *)takeLabel{
    if(!_takeLabel){
        _takeLabel = [UILabel lableWithText:@"" colorString:@"#606266" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _takeLabel;
}

-(UILabel *)remarkLabel{
    if(!_remarkLabel){
        _remarkLabel = [UILabel lableWithText:@"" colorString:@"#909399" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _remarkLabel;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView;
}

-(UILabel *)stopTime{
    if(!_stopTime){
        _stopTime = [UILabel lableWithText:@"" colorString:@"#606266" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _stopTime;
}

-(UILabel *)continueLabel{
    if(!_continueLabel){
        _continueLabel = [UILabel lableWithText:@"继续服药" colorString:kThemeColor textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        [_continueLabel addBorder:kThemeColor lineWidth:1 cornerRidus:viewPix(15)];
    }
    return _continueLabel;
}

@end
